package com.fatri.lessionsimple.util.study

/**
 * 算法
 */
object   Algorithm {
    @JvmStatic
    fun main(args: Array<String>) {
        val arr = intArrayOf(8, 3, 10, 2, 7, 6, 9,8, 12)
        val res=quickSort(arr)

        res.forEach { print("$it ") }

    }
}

/**
 * 快速排序
 */
fun quickSort(arr: IntArray): IntArray {
    if (arr.size <= 1) return arr
    val base = arr[0]
    val left = arr.filter { it < base }.toIntArray()
    val right = arr.filter { it > base }.toIntArray()
    return quickSort(left) + base + quickSort(right)
//    return left+right
}


